package com.fc.system.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.fc.framework.dao.HibernateBaseDAO;
import com.fc.system.entity.DictCode;

@Component("dictCodeDAO")
public class DictCodeDAO extends HibernateBaseDAO<DictCode, Long> {

    public DictCode getByValue(String masterCode, String codeValue) {
        String hql = "FROM DictCode dc WHERE dc.masterCode = :masterCode AND dc.codeValue = :codeValue";
        return (DictCode) this.createQuery(hql).setParameter("masterCode", masterCode)
            .setParameter("codeValue", codeValue).setMaxResults(1).uniqueResult();
    }

    @SuppressWarnings("unchecked")
    public List<DictCode> find(String masterCode) {
        String hql = "FROM DictCode dc WHERE dc.masterCode = :masterCode";
        return this.createQuery(hql).setParameter("masterCode", masterCode).list();
    }
}